package com.settlement.system.model.vo.oms;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;

@Data
public class OriginalOmsOrderVo {

    private String id;
    private String pId;
    private String orderNo;
    private Long storeId;
    private String storeName;
    private String storeTradeNo;
    private String originalNo;
    private String subNo;
    private String status;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime purchasedTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime paymentTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime sendTime;
    private BigDecimal paidAmount;
    private String sku;
    private String productCode;
    private String productName;
    private BigDecimal equalizationAmount;
    private Integer qty;
    // 明细
    private String member;
    private String distributeStatus;
    private String payType;
    private String payStatus;
    private String sendWarehouse;
    private String receiver;
    private String receiverPhone;
    private String receiverMobile;
    private String receiverAddress;
    private String province;
    private String city;
    private String area;
    private String buyName;
    private String distributeType;
    private String depositPayTime;
    private String inTime;
    private String confirmTime;
    private String noticeTime;
    private String distributeTime;
    private String outTime;
    private String suspend;
    private String customerMessage;
    private String sellerRemark;
    private String orderRemark;
    private String preDistributeQty;
    private String spec;
    private String preSendTime;
    private String deliveryNo;
    private String goodsAmount;
    private String goodsTag;
    private String goodsName;
    private String goodsId;
    private String wmsOrderNo;
    private String actPayAmount;
    private String preferInfo;
    private String wmsPushNo;

    /**
     * erp单号
     */
    private String erpNo;

    /**
     * 品牌
     */
    private String brandName;

    public static boolean isDate(String field){
        return "purchasedTime,paymentTime,sendTime".contains(field);
    }

    public static boolean isDecimal(String field){
        return "equalizationAmount,paidAmount".contains(field);
    }

    public static boolean isInteger(String field){
        return "qty".contains(field);
    }

    private static boolean compareDate(LocalDateTime date1, LocalDateTime date2) {
        if (date1 == null && date2 == null) {
            return true;
        }
        if (date1 != null && date2 == null) {
            return false;
        }
        return date1 != null && date1.equals(date2);
    }

    private static boolean compareBigDecimal(BigDecimal value1, BigDecimal value2) {
        if (value1 == null && value2 == null) {
            return true;
        }
        if(Objects.isNull(value2)){
            value2 = BigDecimal.ZERO;
        }
        return value1 != null && value1.compareTo(value2) == 0;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        OriginalOmsOrderVo that = (OriginalOmsOrderVo) o;
        return Objects.equals(orderNo, that.orderNo) && Objects.equals(storeId, that.storeId) && Objects.equals(storeTradeNo, that.storeTradeNo) && Objects.equals(originalNo, that.originalNo) && Objects.equals(subNo, that.subNo) && Objects.equals(status, that.status) && compareDate(purchasedTime, that.purchasedTime) && compareDate(paymentTime, that.paymentTime) && compareDate(sendTime, that.sendTime) && compareBigDecimal(paidAmount, that.paidAmount) && Objects.equals(sku, that.sku) && Objects.equals(productCode, that.productCode) && Objects.equals(productName, that.productName) && compareBigDecimal(equalizationAmount, that.equalizationAmount) && Objects.equals(qty, that.qty) && Objects.equals(member, that.member) && Objects.equals(distributeStatus, that.distributeStatus) && Objects.equals(payType, that.payType) && Objects.equals(payStatus, that.payStatus) && Objects.equals(sendWarehouse, that.sendWarehouse) && Objects.equals(receiver, that.receiver) && Objects.equals(receiverPhone, that.receiverPhone) && Objects.equals(receiverMobile, that.receiverMobile) && Objects.equals(receiverAddress, that.receiverAddress) && Objects.equals(province, that.province) && Objects.equals(city, that.city) && Objects.equals(area, that.area) && Objects.equals(buyName, that.buyName) && Objects.equals(distributeType, that.distributeType) && Objects.equals(depositPayTime, that.depositPayTime) && Objects.equals(inTime, that.inTime) && Objects.equals(confirmTime, that.confirmTime) && Objects.equals(noticeTime, that.noticeTime) && Objects.equals(distributeTime, that.distributeTime) && Objects.equals(outTime, that.outTime) && Objects.equals(suspend, that.suspend) && Objects.equals(customerMessage, that.customerMessage) && Objects.equals(sellerRemark, that.sellerRemark) && Objects.equals(orderRemark, that.orderRemark) && Objects.equals(preDistributeQty, that.preDistributeQty) && Objects.equals(spec, that.spec) && Objects.equals(preSendTime, that.preSendTime) && Objects.equals(deliveryNo, that.deliveryNo) && Objects.equals(goodsAmount, that.goodsAmount) && Objects.equals(goodsTag, that.goodsTag) && Objects.equals(goodsName, that.goodsName) && Objects.equals(goodsId, that.goodsId) && Objects.equals(wmsOrderNo, that.wmsOrderNo) && Objects.equals(actPayAmount, that.actPayAmount) && Objects.equals(preferInfo, that.preferInfo) && Objects.equals(wmsPushNo, that.wmsPushNo);
    }

    @Override
    public int hashCode() {
        return Objects.hash(orderNo, storeId, storeTradeNo, originalNo, subNo, status, purchasedTime, paymentTime, sendTime, paidAmount, sku, productCode, productName, equalizationAmount, qty, member, distributeStatus, payType, payStatus, sendWarehouse, receiver, receiverPhone, receiverMobile, receiverAddress, province, city, area, buyName, distributeType, depositPayTime, inTime, confirmTime, noticeTime, distributeTime, outTime, suspend, customerMessage, sellerRemark, orderRemark, preDistributeQty, spec, preSendTime, deliveryNo, goodsAmount, goodsTag, goodsName, goodsId, wmsOrderNo, actPayAmount, preferInfo, wmsPushNo);
    }
}
